package xyz.zhno.mall.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zhno.mall.common.mpg.entity.OmsOrder;
import xyz.zhno.mall.common.mpg.query.BaseQuery;
import xyz.zhno.mall.common.mpg.vo.BasePage;
import xyz.zhno.mall.order.model.param.OmsOrderParam;
import xyz.zhno.mall.service.OmsOrderService;

import javax.validation.constraints.NotNull;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author liushaoqi
 * @since 2020-12-30
 */
@RestController
@AllArgsConstructor
@RequestMapping("/omsOrder")
public class OmsOrderController {

    private final OmsOrderService omsOrderService;

    /**
     * 分页订单列表
     * @param query 查询参数
     * @return 订单列表
     */
    @GetMapping("/list")
    public BasePage<OmsOrder> list(@Validated BaseQuery query) {

        return  BasePage.newBasePage(
                omsOrderService.page(new Page<OmsOrder>(query.getPageNum(), query.getPageSize())));
    }
    /**
     * 多条件分页查询
     * @param omsOrderParam 查询参数继承分页
     * @return 订单列表
     */
    @GetMapping("/queryList")
    public BasePage<OmsOrder> queryList(@Validated OmsOrderParam omsOrderParam) {
        //条件整合进map
        Map<String,Object> stringTMap=new LinkedHashMap<>();
        stringTMap.put("order_sn",omsOrderParam.getOrderSn() );
        stringTMap.put("receiver_name",omsOrderParam.getReceiverName());
        stringTMap.put("create_time",omsOrderParam.getCreateTime());
        stringTMap.put("status",omsOrderParam.getStatus());
        stringTMap.put("order_type",omsOrderParam.getOrderType());
        stringTMap.put("source_type",omsOrderParam.getSourceType());
        //根据条件查询，为空不拼接
        return  BasePage.newBasePage(
                omsOrderService.page(new Page<OmsOrder>(omsOrderParam.getPageNum(), omsOrderParam.getPageSize()),new QueryWrapper<OmsOrder>()
                        .allEq(stringTMap,false)));
    }





}

